# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=atomicwrites
pkgbase=python-${_realname}
pkgname=("python2-${_realname}" "python3-${_realname}")
pkgver=1.3.0
pkgrel=1
pkgdesc="Atomic file writes on POSIX"
arch=('any')
url="https://github.com/untitaker/python-atomicwrites"
license=('MIT')
makedepends=('python2-setuptools' 'python3-setuptools')
checkdepends=('python2-pytest' 'python3-pytest')
source=("https://files.pythonhosted.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha512sums=('7a257286ba35d6f0db3772ef9666283f29c36719fe35eeb1cb9c36341f0f6a0d7c316d236927ef031f2b8ac6c245320481f51c59e0e1ccf2cbea49065a13d474')

prepare() {
  cd "${srcdir}"
  for builddir in python{2,3}-build-${CARCH}; do
    rm -rf ${builddir} | true
    cp -r "python-${_realname}-${pkgver}" "${builddir}"
  done
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

build() {
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    python${pver} setup.py build
  done  
}

check() {
  export PYTHONPATH=build;${PYTHONPATH}

  msg "Python 2 test for ${CARCH}"
  cd "${srcdir}/python2-build-${CARCH}"
  py.test2

  msg "Python 3 test for ${CARCH}"
  cd "${srcdir}/python3-build-${CARCH}"  
  py.test
}

package_python3-atomicwrites() {
  depends=('python3')

  cd "${srcdir}/python3-build-${CARCH}" 
  python setup.py install --skip-build \
    --optimize=1 \
    --prefix=/usr \
    --root="${pkgdir}"
  install -vDm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -vDm 644 README.rst -t "${pkgdir}/usr/share/doc/${pkgname}"
}

package_python2-atomicwrites() {
  depends=('python2')

  cd "${srcdir}/python2-build-${CARCH}" 
  python2 setup.py install --skip-build \
    --optimize=1 \
    --prefix=/usr \
    --root="${pkgdir}"
  install -vDm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -vDm 644 README.rst -t "${pkgdir}/usr/share/doc/${pkgname}"
}

